using System;
using System.Collections.Generic;
using System.Text;
using AopLoadBalancer.Sample.Client.TestService;
using System.Diagnostics;

namespace AopLoadBalancer.Sample.Client
{
    class Program
    {
        private static void AOPOverheadTest()  
        {
            Service service = new Service();

            Stopwatch stopWatch = Stopwatch.StartNew();
            stopWatch.Stop();

            for (int i = 0; i < 100; i++)
            {
                stopWatch.Reset();
                stopWatch.Start();

                for (int j = 1; j <= i + 1; j++)
                {
                    service.SimpleCall("test");
                }

                stopWatch.Stop();

                Debug.WriteLine(/*i + 1 + ": " +*/ stopWatch.ElapsedMilliseconds);
            }
        }

        private static void LoadBalanceTest()
        {
            Service service = new Service();


            Stopwatch stopWatch = Stopwatch.StartNew();
            stopWatch.Stop();

            for (int i = 0; i < 100; i++)
            {
                stopWatch.Reset();
                stopWatch.Start();

                for (int j = 1; j <= i+1; j++)
                {
                    service.ComplexCall(new RequestMessage());
                }
                stopWatch.Stop();

                Debug.WriteLine(stopWatch.ElapsedMilliseconds);
            }
        }

        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start testing ...");
            Console.ReadKey();

            //AOP overhead testing
            //AOPOverheadTest();

            //Load balancing testin
            LoadBalanceTest();

            Console.ReadKey();
        }
    }
}
